<?php
/**
 * Html.php
 *
 * @category    Madoqua
 * @package     Filter
 */

/** filter interface */
require_once 'Zend/Filter/Interface.php';

/** html purifier */
require_once 'HtmlPurifier/HTMLPurifier.standalone.php';

/**
 * Madoqua_Filter_Html
 *
 * @category    Madoqua
 * @package     Filter
 */
class Madoqua_Filter_Html implements Zend_Filter_Interface
{
    /**
     * html purifier
     *
     * @var HTMLPurifier
     */
    protected $_purifier;
    
    /**
     * constructor
     * 
     * sets up the purifier
     */
    public function __construct()
    {
        $config = HTMLPurifier_Config::createDefault();
        //configuration for the purifier
        $config->set('HTML', 'Doctype', 'XHTML 1.0 Strict');
        //use xhtml strict doctype (because we CARE)
        $config->set('Cache', 'SerializerPath', Madoqua_Application::getDataDirectory() . DIRECTORY_SEPARATOR  . 'cache/purifier/');
        //set proper cache dir
        $config->set('URI', 'Base', Madoqua_Application::getConfiguration()->url);
        $config->set('URI', 'MakeAbsolute', true);
        //make urls absolute (and point to the right url)
        $config->set('AutoFormat', 'AutoParagraph', true);
        //automatically wrap text in paragraphs
        
        $this->_purifier = new HTMLPurifier($config);
        //purifier
    }
    
    /**
     * Returns the result of filtering $value
     *
     * @param  mixed $value
     * @throws Zend_Filter_Exception If filtering $value is impossible
     * @return mixed
     */
    public function filter($value) {
        return $this->_purifier->purify($value);
    }
}
